package com.darco.darcoapp;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

	
	public class AdapterListCard extends ArrayAdapter<String> {

	    private LayoutInflater mInflater;
	    
	    private String[] cardNames;
	    private String[] cardCategories;
	    private String[] cardIDs;
	    private Bitmap[] cardPreviews;
	    
	    private int mViewResourceId;
	    
	    public AdapterListCard(Context ctx, int viewResourceId, String[] name, String[] cat, String[] id, Bitmap[] prev) {
	        super(ctx, viewResourceId, name);
	        
	        mInflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	        
	        cardNames=name;
	        cardCategories=cat;
	        cardIDs=id;
	        cardPreviews=prev;
	        
	        mViewResourceId = viewResourceId;
	    }

	    @Override
	    public int getCount() {
	        return cardNames.length;
	    }

	    @Override
	    public String getItem(int position) {
	        return cardNames[position];
	    }

	    @Override
	    public long getItemId(int position) {
	        return position;
	    }

	    @Override
	    public View getView(int position, View convertView, ViewGroup parent) {
	        convertView = mInflater.inflate(mViewResourceId, null);
	        
	        ImageView iv = (ImageView)convertView.findViewById(R.id.element_cardPreview_imageView);
	        iv.setImageBitmap(cardPreviews[position]);

	        TextView nm = (TextView)convertView.findViewById(R.id.element_cardName_textView);
	        nm.setText(cardNames[position]);
	        
	        TextView ct = (TextView)convertView.findViewById(R.id.element_cardCat_textView);
	        ct.setText(cardCategories[position]);
	        
	        TextView id = (TextView)convertView.findViewById(R.id.element_cardID_textView);
	        id.setText(cardIDs[position]);
	        
	        return convertView;
	    }
	}


